package ${basePackage}.service.impl;

import ${basePackage}.dao.${className}Dao;
import ${basePackage}.entity.${className};
import ${basePackage}.service.${className}Service;
import com.esunrising.esungsc.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Optional;


@Service
public class ${className}ServiceImpl extends BaseServiceImpl<${className}Dao, ${className}> implements ${className}Service {

    @Resource
    private ${className}Dao dao;

    @Override
    public void syncSave(${className} entity) {
        // 如果存在，则先删除
        Optional<${className}> byId = dao.findById(entity.getId());
        byId.ifPresent( doc -> {
            dao.deleteById(doc.getId());
        });
        // 保存数据
        super.save(entity);
    }

    @Override
    public ${className} findById(String id){
        Optional<${className}> byId = dao.findById(id);
        return byId.orElse(null);
    }

}